AutoMapper. Mapper. CreateMap reports "System. NullReferenceException: the object reference is not set to the instance of the object ." Recurrence of exceptions,
Navigation:
> I. problems during the National Day holiday
> II. An exception occurs again on weekends.
> III. troubleshooting
> IV. Abnormal Replay
> V. Post-repair monitoring
> VI. End
I. TOP problems during the National Day holiday
During the National Day holiday-July 22, October 5-the paym
AutoMapper. Mapper. CreateMap reports "System. NullReferenceException: the object reference is not set to the instance of the object ." Recurrence of exceptions,
Navigation:
> I. problems during the National Day holiday
> II. An exception occurs again on weekends.
> III. troubleshooting
> IV. Abnormal Replay
> V. Post-repair monitoring
> VI. End
I. TOP problems during the National Day holiday
During the National Day holiday-July 22, October 5-the paym
with caution) ** @ param key * attribute name * @ param value * attribute value * @ return number of updated records */public Integer updateProperty (String key, Object value) {HqlUpdateBuilder builder = new HqlUpdateBuilder (); String hql = builder. param (key, value ). toHql (); return update (hql, key, value);}/*** update based on 0, 1, or multiple attributes (it is strongly recommended that, use at least 2 key-value pairs) */public Integer updateProperties (Pair... pair) {HqlUpdateBuilder b
AutoMapper and ASP. net mvc. Generally, AutoMapper is used in the Controller Action to convert the Presentation Model passed by the front-end to the Entity Model in the corresponding business logic. if you write AutoMapper in the Action. createMap
First, define a MyProfile, inherit from the Profile class of AutoMapper, and override the Configure () method to Configure it in this method.[Csharp]Public class OrderDomainMvcProfile: Profile{Public overr
(T)map.get(this); // Maps are constructed lazily. if the map for this thread // doesn't exist, create it, with this ThreadLocal and its // initial value as its only entry. T value = initialValue(); createMap(t, value); return value; }
The get () method first obtains the current thread and then calls getMap (). The API method is as follows:
ThreadLocalMap getMap(Thread t) { return t.threadLocals
? I am using DTO for data transmission at the presentation layer and application service layer, however, in the end, all these DTO functions must be converted into entities to directly deal with databases. If each dto needs to be manually converted to the corresponding entity, the workload cannot be underestimated.If you are smart, you will surely think of some ways to reduce this workload.
4. use AutoMapper to automatically map DTO to objects
1. Brief introduction to AutoMapper
If you are not f
, with this ThreadLocal and its //initial value as its onl Y entry. T value = InitialValue (); Createmap (t, value); return value; }The Get () method first obtains the current thread, and then calls Getmap (), the API method is as follows: Threadlocalmap Getmap (Thread t) { return t.threadlocals; }Getmap () returns the Threadlocals variable in the current thread, as we said before, a variable of type threadl
you refute me, you have no reason, so now), define it as int type, if we want to map aliens to humans, it is actually the ing between uint and int:
Namespace FrontAutoMapper {class Program {static void Main (string [] args) {// creates a ing. The Age ing condition is that the Age attribute of the source type is within the range (0,149). Mapper. createMap
In this example, the Age is mapped to an alien within the range (0,149). The result is as follow
AutoMapper (5), automapperTotal returned directory
Dynamic and ExpandoObject ing
AutoMapper can map or map from a dynamic (dynamic) object to a dynamic object without any configuration.
Namespace extends thautomapper {// defines a Person class public class Person {public int Age {get; set;} public string Name {get; set ;}} // Main Program class Program {static void Main (string [] args) {// ing is also possible without CreateMap, which is called "Zero
(if you refute me, you have no reason, so now), define it as int type, if we want to map aliens to humans, it is actually the ing between uint and int:
Namespace FrontAutoMapper {class Program {static void Main (string [] args) {// creates a ing. The Age ing condition is that the Age attribute of the source type is within the range (0,149). Mapper. createMap
In this example, the Age is mapped to an alien within the range (0,149). The result is as fo
, as seen in source code fragment 5-5.Figure 5-5 Threadlcoal.set Source code fragmentThe first code in Figure 5-5 takes out the current thread T. The Getmap (t) method is then called when the current thread is passed in, in other words. The Threadlocalmap returned by this method has something to do with the current thread, which we'll record first.Further determine that the map is not empty. Then the key set to the map is this. The value is the externally passed-in argument. What is this? is the
create a copy of the resource, which you can see from the code is the call to the Setinitialvalue () method, which is defined as follows:1/** 2 * Variant of Set () to establish initialvalue. Used instead 3 * of Set () in case user has overridden the set () method. 4 * 5 * @return The initial value 6
*/7 Private T Setinitialvalue () {8 t value = InitialValue (); 9 Thread T = Thread.CurrentThread (); Localmap map = getmap (t); one if (map! = null) Map.set (this, val
map was maintained
* by the ThreadLocal class. *
/Threadlocal.threadlocalmap threadlocals= null;
...
}
Here we have the initialization process of holding variable threadlocals through source code analysis thread.
Let's take a look at the initialization method:
public class Threadlocal
You can see that the Createmap (thread T, t firstvalue) method initializes the threadlocals in the thread class.
And then trace the Threadloc
AutoMapper Porter ConfigurationReview
In the previous articles, we used the basic usage and custom ing of AutoMapper. I believe some of you can use the powerful Mapping tool of AutoMapper. However, do you still remember that the previous articles mentioned that Map creation does not require Create every time? What if AutoMapper manages this? In this article, we will look at the AutoMapper configuration.Initialization
AutoMapper provides an initialization function (Mapper. Initialize) that can be
thread"? Let's take a look at how the source code of the Threadlocal set () method is implemented: /** * Sets the current thread's copy of this thread-local variable * to the specified value. Most subclasses'll has a no need to * override this method, and relying solely on the {@link #initialValue} * method To set the values of Thread-locals. * * @param value The value of the stored in the current thread's copy of * this thread-local.
thread‘s copy of * this thread-local. */public void set(T value) { Thread t = Thread.currentThread(); ThreadLocalMap map = getMap(t); if (map != null) map.set(this, value); else createMap(t, value);}There is no magic, inside this method we see that we first get a threadlocalmap related to the current thread through the Getmap (thread T) method, and then set the value of the variable to this Threadlocalmap object, Of c
Directory
Analysis of Threadlcoal Source code
Garbage collection of Threadlocal
Java reference
Recycling of Threadlocal
Recycling of Threadlocalmap in each thread
Memory leak issues
Summarize
Reference
Analysis of Threadlcoal Source code
We know that threadlocal is used to maintain multiple thread-thread- independent copies of variables that are shared only within threads , across methods, classes, and so on, a threadlocal that maintains multiple th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.